package com.qidian.k12.service.impl;

import com.qidian.k12.pojo.Student;
import com.qidian.k12.mapper.StudentMapper;
import com.qidian.k12.service.StudentService;
import com.qidian.k12.util.K12Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (Student)表服务实现类
 *
 * @author makejava
 * @since 2021-10-28 09:02:10
 */
@Service("studentService")
public class StudentServiceImpl implements StudentService {
    @Resource
    private StudentMapper studentMapper;

    public K12Result queryByNameAndNo(String no, String name){
        return K12Result.ok(studentMapper.queryByNameAndNo(no,name));
    }

    /**
     * 通过ID查询单条数据
     *
     * @param studentNo 主键
     * @return 实例对象
     */
    @Override
    public Student queryById(String studentNo) {
        return this.studentMapper.queryById(studentNo);
    }


    /**
     * 新增数据
     *
     * @param student 实例对象
     * @return 实例对象
     */
    @Override
    public Student insert(Student student) {
        this.studentMapper.insert(student);
        return student;
    }

    /**
     * 修改数据
     *
     * @param student 实例对象
     * @return 实例对象
     */
    @Override
    public Student update(Student student) {
        this.studentMapper.update(student);
        return this.queryById(student.getStudentNo());
    }

    /**
     * 通过主键删除数据
     *
     * @param studentNo 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String studentNo) {
        return this.studentMapper.deleteById(studentNo) > 0;
    }
}
